package com.xiaoluo.a17_countdown;

import android.content.Context;
import android.graphics.Color;
import android.view.Gravity;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.TextView;


/**
 * @ Created on: 2020/4/3
 * @Author: LEGION XiaoLuo
 * @ Description:
 */
public class CountDownView extends FrameLayout {
    private Context mContext;
    private TextView mTitleView;
    private TextView mCountDownText;
    private TimeCount mCount;

    public CountDownView(Context context) {
        super(context);
        mContext = context;
        init();
    }

    private void init() {
        setLayoutParams(new LayoutParams(UiUtil.div(1920), UiUtil.div(1080)));

        mTitleView = new TextView(mContext);
        mTitleView.setText("用户连接已断开");
        LayoutParams titleParams = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        titleParams.topMargin = UiUtil.div(380);
        mTitleView.setLayoutParams(titleParams);
        mTitleView.setTextSize(UiUtil.dpi(30));
        mTitleView.setTextColor(Color.parseColor("#000000"));
        mTitleView.setGravity(Gravity.CENTER_HORIZONTAL);
        mTitleView.setIncludeFontPadding(false);
        mTitleView.getPaint().setFakeBoldText(true);
        addView(mTitleView, titleParams);


        mCountDownText = new TextView(mContext);
        LayoutParams countDownParams = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        countDownParams.topMargin = UiUtil.div(480);
        mCountDownText.setTextSize(UiUtil.dpi(30));
        mCountDownText.setGravity(Gravity.CENTER_HORIZONTAL);
        mCountDownText.setIncludeFontPadding(false);
        addView(mCountDownText, countDownParams);
    }

    public void start(long time, long interval) {
        mCount = new TimeCount(time + 1000, interval, mCountDownText);
        mCount.start();

    }

    public void cancel() {
        mCount.cancel();
    }

}
